<?php


namespace app\server\controller;

use app\server\model\CouponOrder as CouponOrderModel;
use app\index\controller\Base;

class Couponorder extends Base
{
   
    public function get()
    {
        $data = $this->request->param();
        $res = new CouponOrderModel();
        $r=$res->with("Coupon.couponServers,user")
            ->where($data['field'],$data['op'],$data['value'])
            ->where('cTime',['>=',$data['start_time']],['<=',$data['end_time']],'and')
            ->order('cTime desc')
            ->page($data['page'])
            ->limit(10)
            ->select();
        return $r;
    }
    public function getmy()
    {
        $data = $this->request->param();
        $res = new CouponOrderModel();
        return $res->with("Coupon.couponServers,user")
            ->where('u_id','=',$data['u_id'])
            ->where('use_num<num')
            ->order('cTime desc')
            ->page($data['page'])
            ->limit(10)
            ->select();
    }
    public function save()
    {
        $res = new CouponOrderModel();
        $data = $this->request->param();
        $res->saveModel($data);
    }
    public function update()
    {
        $res = new CouponOrderModel();
        $data = $this->request->param();
        $res->updateModel($data);
    }
    public function num(){
        $data = $this->request->param();
        $res =new CouponOrderModel();
        return $res->where($data['field'],$data['op'],$data['value'])->count();
    }
    public function useNumInc(){
        $res = new CouponOrderModel();
        $data = $this->request->param();
        $res->where([$data['field']=>$data['value']])->setInc('use_num');
    }
    public function useNumDec(){
        $res = new CouponOrderModel();
        $data = $this->request->param();
        $res->where([$data['field']=>$data['value']])->setDec('use_num');
    }
}